home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / dos / diverses / cexpress / strings / padright.asm < prev    next >
Encoding:
Assembly Source File  |  1989-05-03  |  1.4 KB  |  56 lines

  1. ;void  pad_right(strg,ch,length);
  2. ;  unsigned char  *strg,ch;
  3. ;  unsigned short  length;
  4.  
  5.     EXTRN  _memory_model:byte
  6.     EXTRN  _error_code:byte
  7.  
  8. _TEXT    SEGMENT BYTE PUBLIC 'CODE'
  9.     ASSUME CS:_TEXT
  10.     PUBLIC _pad_right
  11. _pad_right proc near
  12.     push bp            ;
  13.     mov  bp,sp        ;set up stack frame
  14.     push di            ;
  15.     cmp  _memory_model,0    ;near or far?
  16.     jle  begin        ;jump if near
  17.     inc  bp            ;else add 2 to BP
  18.     inc  bp            ;
  19. begin:    mov  _error_code,1    ;1 = error
  20.     cmp  _memory_model,2    ;data near or far?
  21.     jb   L0            ;jump if near
  22.     les  di,dword ptr[bp+4] ;get string address
  23.     inc  bp            ;add 2 to BP since dword ptr
  24.     inc  bp            ;
  25.     jmp  short L1        ;jump ahead
  26. L0:    mov  di,[bp+4]        ;near case
  27.     mov  ax,ds        ;ES = DS
  28.     mov  es,ax        ;
  29. L1:    mov  si,di        ;copy ptr start position
  30. L2:    cmp  byte ptr es:[di],0 ;move DI to end of string
  31.     je   L3            ;
  32.     inc  di            ;
  33.     jmp  short L2        ;
  34. L3:    mov  cx,di        ;counter
  35.     sub  cx,si        ;string length
  36.     sub  bx,bx        ;
  37.     mov  bl,[bp+8]        ;new string length
  38.     cmp  cl,bl        ;compare the two lengths
  39.     jae  L4            ;quit if old len>=new len
  40.     sub  bx,cx        ;bx = number pad chars to write
  41.     mov  cx,bx        ;use as counter    
  42.     mov  al,[bp+6]        ;get pad character
  43.     cld            ;direction forward
  44.     rep  stosb        ;write the pad characters
  45.     mov  byte ptr es:[di],0    ;add terminator
  46.     dec  _error_code    ;0 = no error
  47. L4:    pop  di            ;
  48.     pop  bp            ;
  49.     cmp  _memory_model,0    ;quit
  50.     jle  quit        ;
  51.     db   0CBh        ;RET far
  52. quit:    ret            ;RET near
  53. _pad_right ENDP
  54. _TEXT    ENDS
  55.     END
  56.